package com.ftg.learn.execl.util;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.util.StringUtils;
import com.ftg.learn.execl.domain.StudentDomain;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 通用部分设计
 *
 * @author 布衣
 */
@Slf4j
public class ExeclUtil implements ReadListener<StudentDomain> {

    //存储的数据
    private final List<StudentDomain> dataList = new ArrayList<>();

    @Override
    public void invoke(StudentDomain userData, AnalysisContext analysisContext) {
        // user

        if(!StringUtils.isBlank(userData.getId()) && !StringUtils.isBlank(userData.getName()) && !StringUtils.isBlank(userData.getGender())){
            log.info("读取到一条数据: {} {}", userData.getName(), userData.getClassName());
            dataList.add(userData);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完成");
    }

    public List<StudentDomain> getDataList() {
        return dataList;
    }
}
